/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package GUI;

import java.awt.Color;
import java.awt.Graphics;
import java.awt.Image;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;

import javax.imageio.ImageIO;
import javax.swing.JFileChooser;

import main.filter.FactFilter;
import main.location.Location;
import main.model.Defines;
import main.model.json.JsonFile;
import main.model.rdf.FilterElement;
import main.model.rdf.FilterElement.MODE;
import main.model.rdf.FilterElement.TYPE;
import main.model.rdf.RDF;
import main.model.rdf.RdfField;

/**
 *
 * @author mAnTi
 */
public class GUI extends javax.swing.JDialog {

	/**
	 * Kolekcja zawierajaca baze faktów.
	 */
	RDF[] aRdf = null;

	/**
	 * Kolekcja zawierajaca czesci zapytania do bazy faktow.
	 */
	Map<String, FilterElement> choosenFilters 
		= new HashMap<String, FilterElement>();

	/**
	 * Kolekcje zawierajace odpowiednio wszystkie wyniki oraz przefiltrowane wyniki.
	 */
	List<RDF> result = null,
		filtredResult = null;
	
	
	List<String> objects = new ArrayList<String>(),
    		predicats = new ArrayList<String>(),
    		subjects = new ArrayList<String>(),
    		objects_types = new ArrayList<String>(),
    		predicats_types = new ArrayList<String>(),
    		subjects_types = new ArrayList<String>();
	

	String locationType = "filtrowanie lokacji";
	String dateType = "filtrowanie dat";
	List<String> locationLex = new ArrayList<String>();
	List<String> dateLex = new ArrayList<String>();
	
    /**
	 * 
	 */
	private static final long serialVersionUID = 3627371625755217404L;
	/**
     * Creates new form GUI
     */
    public GUI(java.awt.Frame parent, boolean modal) {
        super(parent, modal);
        initComponents();
        l_w_promieniu1.setVisible(false);
        w_promieniu.setVisible(false);
        w_promieniu2.setVisible(false);
        w_promieniu1.setVisible(false);
        l_data.setVisible(false);
        data2.setVisible(false);
        data1.setVisible(false);
        data.setVisible(false);
        data.setForeground(new Color(0));
        data1.setForeground(new Color(0));
        data2.setForeground(new Color(0));
        searchvalue.setForeground(new Color(0));
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings({ "unchecked", "rawtypes" })
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        spojniklogiczny = new javax.swing.ButtonGroup();
        subjectsCB = new javax.swing.JComboBox();
        predicateCB = new javax.swing.JComboBox();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jScrollPane1 = new javax.swing.JScrollPane();
        jList1 = new javax.swing.JList();
        jLabel4 = new javax.swing.JLabel();
        jScrollPane2 = new javax.swing.JScrollPane();
        jList2 = new javax.swing.JList();
        jLabel5 = new javax.swing.JLabel();
        search_main = new javax.swing.JButton();
        search_main2 = new javax.swing.JButton();
        sl_lub = new javax.swing.JRadioButton();
        sl_i = new javax.swing.JRadioButton();
        loadfileBT = new javax.swing.JButton();
        saveFileBT = new javax.swing.JButton();
        btnClear = new javax.swing.JButton();
        loadfile1 = new javax.swing.JButton();
        jSeparator1 = new javax.swing.JSeparator();
        type_predicateCB1 = new javax.swing.JComboBox();
        searchvalue = new javax.swing.JTextField();
        type_sujbcetjCB = new javax.swing.JComboBox();
        type_objectCB = new javax.swing.JComboBox();
        objectCB = new javax.swing.JComboBox();
        l_w_promieniu1 = new javax.swing.JLabel();
        w_promieniu = new javax.swing.JTextField();
        w_promieniu2 = new javax.swing.JTextField();
        w_promieniu1 = new javax.swing.JTextField();
        l_data = new javax.swing.JLabel();
        data2 = new javax.swing.JTextField();
        data1 = new javax.swing.JTextField();
        data = new javax.swing.JTextField();
        jLabel6 = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("RDF");
        setPreferredSize(new java.awt.Dimension(700, 550));
        getContentPane().setLayout(null);

        subjectsCB.setEditable(true);
        subjectsCB.setMaximumRowCount(10);
        subjectsCB.setBorder(null);
        
        subjectsCB.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                sujbcetjCBActionPerformed(evt);
            }
        });
        
        subjectsCB.getEditor().getEditorComponent().addKeyListener(new KeyListener(){

			@Override
			public void keyPressed(KeyEvent arg0) {
				// TODO Auto-generated method stub
				
			}

			@Override
			public void keyReleased(KeyEvent arg0) {
				if (subjectsCB.getEditor().getItem()!= null)
				{
					String val = subjectsCB.getEditor().getItem().toString();
					
					for(String s : subjects)
					{
						if (s.contains(val))
						{
							subjectsCB.setSelectedItem(s);
							break;
						}
					}
				}
			}

			@Override
			public void keyTyped(KeyEvent arg0) {
				
			}});
        
        getContentPane().add(subjectsCB);
        subjectsCB.setBounds(30, 50, 152, 37);

        predicateCB.setEditable(true);
        predicateCB.setBorder(null);
        predicateCB.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {

                l_data.setVisible(false);
                data2.setVisible(false);
                data1.setVisible(false);
                data.setVisible(false);
	           	 l_w_promieniu1.setVisible(false);
	             w_promieniu.setVisible(false);
	             w_promieniu2.setVisible(false);
	             w_promieniu1.setVisible(false);
                
             	if (isLocationFiltered())
                {
                    l_w_promieniu1.setVisible(true);
                    w_promieniu.setVisible(true);
                } 
                
                if (isDateFiltered())
                {

                    l_data.setVisible(true);
                    data1.setVisible(true);
                    data.setVisible(true);
                }
            }
        });
        predicateCB.getEditor().getEditorComponent().addKeyListener(new KeyListener(){

			@Override
			public void keyPressed(KeyEvent arg0) {
				// TODO Auto-generated method stub
				
			}

			@Override
			public void keyReleased(KeyEvent arg0) {
				if (predicateCB.getEditor().getItem()!= null)
				{
					String val = predicateCB.getEditor().getItem().toString();
					
					for(String s : predicats)
					{
						if (s.contains(val))
						{
							predicateCB.setSelectedItem(s);
							break;
						}
					}
				}
			}

			@Override
			public void keyTyped(KeyEvent arg0) {
				
			}});
        
        
        getContentPane().add(predicateCB);
        predicateCB.setBounds(200, 50, 150, 37);

        jLabel1.setText("Podmiot");
        getContentPane().add(jLabel1);
        jLabel1.setBounds(30, 30, 60, 14);

        jLabel2.setText("Predykat");
        getContentPane().add(jLabel2);
        jLabel2.setBounds(200, 30, 60, 14);

        jLabel3.setText("Obiekt");
        getContentPane().add(jLabel3);
        jLabel3.setBounds(370, 30, 130, 14);

        jList1.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(102, 102, 102)));
        jScrollPane1.setViewportView(jList1);

        getContentPane().add(jScrollPane1);
        jScrollPane1.setBounds(30, 170, 494, 98);

        jLabel4.setText("Lista wprowadzonych trójek");
        getContentPane().add(jLabel4);
        jLabel4.setBounds(30, 150, 185, 14);

        jList2.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(102, 102, 102)));
        jScrollPane2.setViewportView(jList2);

        getContentPane().add(jScrollPane2);
        jScrollPane2.setBounds(30, 300, 494, 200);

        jLabel5.setText("Uzyskane wyniki");
        getContentPane().add(jLabel5);
        jLabel5.setBounds(30, 280, 210, 14);

        search_main.setText("Dodaj");
        search_main.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                search_mainActionPerformed(evt);
                
                
                FilterElement tmp = new FilterElement(
                		(String) subjectsCB.getSelectedItem(), 
                		(String) type_sujbcetjCB.getSelectedItem(), 
                		(String) predicateCB.getSelectedItem(), 
                		(String) type_predicateCB1.getSelectedItem(), 
                		(String) objectCB.getSelectedItem(), 
                		(String) type_objectCB.getSelectedItem(), 
                		(sl_lub.isSelected()?TYPE.OR:TYPE.AND)
                		);
                
                if (subjectsCB.getSelectedItem() == null ||
                		((String)subjectsCB.getSelectedItem()).isEmpty())
                {
                	objects.add(tmp.toString());
                	objectCB.setModel(new javax.swing.DefaultComboBoxModel(objects.toArray()));
                }
                
                if(tmp.getObject().toString().contains("<,"))
                {
                	tmp.setMode(MODE.NESTED);                	
                	FilterElement subelement = choosenFilters.get(
                			tmp.getObject().toString());
                	
                	if(subelement.getMode() == MODE.NESTED)
                		subelement.setMode(MODE.NESTED_SUBFILTER);
                	else
                		subelement.setMode(MODE.SUBFILTER);
                }
                
                if(isLocationFiltered())
                {
                	if (w_promieniu.getText() != null && !w_promieniu.getText().isEmpty())
                    {
                		tmp.setMode(MODE.LOCATION);
                		tmp.setRadius(Double.parseDouble(
                				w_promieniu.getText()));
                    }
                }
                
                if(isDateFiltered())
                {
                	if (data.getText() != null && !data.getText().isEmpty() ||
                    		data1.getText() != null && !data1.getText().isEmpty())
                	{
	                	tmp.setMode(MODE.DATE);
	                	tmp.setBefore(data.getText());
	                	tmp.setAfter(data1.getText());
                	}
                }
                
                choosenFilters.put(tmp.toString(), tmp);
                
                subjectsCB.setSelectedItem(null);
                type_sujbcetjCB.setSelectedItem(null);
                predicateCB.setSelectedItem(null);
                type_predicateCB1.setSelectedItem(null);
                objectCB.setSelectedItem(null);
                type_objectCB.setSelectedItem(null);
                
                jList1.setListData(choosenFilters.values().toArray());               
                
                
            }
        });
        getContentPane().add(search_main);

        search_main2.setText("Wyszukaj");
        search_main2.addActionListener(new java.awt.event.ActionListener() { 
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                search_mainActionPerformed(evt); 
                
                if (choosenFilters.size() > 0)
                {
                    FactFilter filter = new FactFilter();
            		filter.setFacts(Arrays.asList(aRdf));
            		FactFilter subfilter = new FactFilter();
                	boolean first = true;
                	boolean firstSubfiltration = true;
                	
                	for(Entry<String, FilterElement> e : choosenFilters.entrySet())
                	{
                		FilterElement element = e.getValue();
                		
                		if(element.getMode() != MODE.SUBFILTER && 
                				element.getMode() != MODE.NESTED_SUBFILTER)
                		{
                    		if(element.getMode() == MODE.DATE)
                    		{
                    			filter.filterDate(
                    					element.getAfter(), element.getBefore());
                    			System.out.println("");
                    		}
                    		
                    		if(element.getMode() == MODE.LOCATION)
                    		{
                    			String latitude = null,
                    					longitude = null;
                    			
                    			subfilter.setFacts(Arrays.asList(aRdf));
                    			
                    			RDF latitudeRdf = new RDF(
                    					new RdfField(element.getSubject(), element.getSubjectType()), 
                						new RdfField(Defines.EMPTY_STRING, Defines.EMPTY_STRING),
                						new RdfField(Defines.EMPTY_STRING, Defines.LATITUDE_TYPE));
                    			latitude = subfilter.findFact(latitudeRdf).getObject().getName();
                    			
                    			RDF longitudeRdf = new RDF(
                    					new RdfField(element.getSubject(), element.getSubjectType()), 
                						new RdfField(Defines.EMPTY_STRING, Defines.EMPTY_STRING),
                						new RdfField(Defines.EMPTY_STRING, Defines.LONGITUDE_TYPE));
                    			longitude = subfilter.findFact(longitudeRdf).getObject().getName();
                    			
                    			if ((latitude != null) && (longitude != null))
                    			{
	                    			Location location = new Location(latitude, longitude);
	                    			filter.filterLocation(location, element.getRadius()); 
                    			}
                    		}
                			
                			if(first)
                			{
                				element.setType(TYPE.OR);
	                			first = false;
                			}
                			
	                		if(element.getMode() == MODE.NESTED)
	                		{
	                			firstSubfiltration = filterNested(filter,
	                					element,
	                					firstSubfiltration);
	                		}
	                		else
		                	{
	                			if(element.getMode() == MODE.LOCATION)
	                    		{
	                    			String latitude = null,
	                    					longitude = null;
	                    			
	                    			subfilter.setFacts(Arrays.asList(aRdf));
	                    			
	                    			RDF latitudeRdf = new RDF(
	                    					new RdfField(element.getSubject(), element.getSubjectType()), 
	                						new RdfField(Defines.EMPTY_STRING, Defines.EMPTY_STRING),
	                						new RdfField(Defines.EMPTY_STRING, Defines.LATITUDE_TYPE));
	                    			latitude = subfilter.findFact(latitudeRdf).getObject().getName();
	                    			
	                    			RDF longitudeRdf = new RDF(
	                    					new RdfField(element.getSubject(), element.getSubjectType()), 
	                						new RdfField(Defines.EMPTY_STRING, Defines.EMPTY_STRING),
	                						new RdfField(Defines.EMPTY_STRING, Defines.LONGITUDE_TYPE));
	                    			longitude = subfilter.findFact(longitudeRdf).getObject().getName();
	                    			
	                    			if ((latitude != null) && (longitude != null))
	                    			{
		                    			Location location = new Location(latitude, longitude);
		                    			filter.filterLocation(location, element.getRadius()); 
	                    			}
	                    			continue;
	                    		}
	                			
	                			if(element.getMode() == MODE.DATE)
	                    		{
	                    			filter.filterDate(
	                    					element.getBefore(), element.getAfter());
	                    			continue;
	                    		}                    		
	                			
		                		if (e.getValue().getType() == TYPE.AND)
		                		{
		                			filter.filterAnd(
		                					element.toRDF());
		                		} 
		                		else 
		                			filter.filterOr(element.toRDF());
		                	}
	                	}
	                }
                	result = filter.getResult();
                	filtredResult = result;
                	jList2.setListData(filtredResult.toArray());
                }
            }

			private boolean filterNested(FactFilter filter,
					FilterElement element,
					boolean firstSubfiltration)
			{
				FactFilter subfilter = new FactFilter();				
				FilterElement parent = element;
								
				ArrayList<FilterElement> list = new ArrayList<FilterElement>();
				while(parent.getMode() != MODE.SUBFILTER) 
				{
					list.add(parent);
					parent = choosenFilters.get(
							parent.getObject().toString());
				}

				for(int i = list.size() - 1; i >= 0; i--) 
				{
					
					if (firstSubfiltration) 
					{
						subfilter.setFacts(Arrays.asList(aRdf));
						firstSubfiltration = false;
					}
					else
					{
						ArrayList<RDF> filteredFacts = new ArrayList<RDF>();
						for(RDF rdf : filter.getResult()) 
						{
							RDF copy = new RDF(rdf.getSubject(), 
									rdf.getProperty(),
									rdf.getObject());
							filteredFacts.add(copy);
						}
						subfilter.setFilteredFacts(filteredFacts);
					}
					subfilter(filter, subfilter, list.get(i));
				}
				return firstSubfiltration;
			}

			private void subfilter(FactFilter filter,
					FactFilter subfilter,
					FilterElement element)
			{
				if (element.getType() == TYPE.AND) 
				{
					subfilter.filterAnd(choosenFilters.get(
							element.getObject().toString()).toRDF());
					filter.filterAnd(element.toRDF(), subfilter);
				}
				else 
				{
					subfilter.filterOr(choosenFilters.get(
							element.getObject().toString()).toRDF());
					filter.filterOr(element.toRDF(), subfilter);
				}
			}
        });
        getContentPane().add(search_main2);
        
        spojniklogiczny.add(sl_lub);
        sl_lub.setText("lub");
        getContentPane().add(sl_lub);
        sl_lub.setBounds(539, 49, 49, 17);

        spojniklogiczny.add(sl_i);
        sl_i.setText("i");
        getContentPane().add(sl_i);
        sl_i.setBounds(539, 69, 27, 17);

        loadfileBT.setText("Wczytaj z pliku");
        loadfileBT.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                loadfileBTActionPerformed(evt);
            }
        });
        getContentPane().add(loadfileBT);
        
        saveFileBT.setText("Zapisz do pliku");
        saveFileBT.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
            	JFileChooser WybierzPlik = new JFileChooser(); 
                WybierzPlik.showSaveDialog(null);
                File Plik = WybierzPlik.getSelectedFile();
                JsonFile.save(Plik.toPath().toString(), result);

            }
        });
        getContentPane().add(saveFileBT);
        
        
        btnClear.setText("Wyczyść");
        btnClear.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
            	jList1.setListData(new Object[0]);
            	jList2.setListData(new Object[0]);
            	choosenFilters = new HashMap<String, FilterElement>();
            	result = new ArrayList<RDF>();
            	filtredResult = new ArrayList<RDF>();
            }
        });
        getContentPane().add(btnClear);
        
        search_main.setBounds(540, 160, 130, 37);
        search_main2.setBounds(540, 200, 130, 37);
        loadfileBT.setBounds(540, 240, 130, 36);
        saveFileBT.setBounds(540, 280, 130, 36);
        btnClear.setBounds(540, 320, 130, 36);
        
        loadfile1.setText("Przeszukaj");
        loadfile1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                String val = searchvalue.getText();
                filtredResult = new ArrayList<RDF>();
                for(RDF r : result)
                {
                	if (r.toString().contains(val))
                	{
                		filtredResult.add(r);
                	}
                }
                
                jList2.setListData(filtredResult.toArray());
            }
        });
        getContentPane().add(loadfile1);
        loadfile1.setBounds(539, 462, 128, 36);
        getContentPane().add(jSeparator1);
        jSeparator1.setBounds(0, 509, 685, 10);

        type_predicateCB1.setEditable(true);
        type_predicateCB1.setBorder(null);
        getContentPane().add(type_predicateCB1);
        type_predicateCB1.getEditor().getEditorComponent().addKeyListener(new KeyListener(){

			@Override
			public void keyPressed(KeyEvent arg0) {
				// TODO Auto-generated method stub
				
			}

			@Override
			public void keyReleased(KeyEvent arg0) {
				if (type_predicateCB1.getEditor().getItem()!= null)
				{
					String val = type_predicateCB1.getEditor().getItem().toString();
					
					for(String s : predicats_types)
					{
						if (s.contains(val))
						{
							type_predicateCB1.setSelectedItem(s);
							break;
						}
					}
				}
			}

			@Override
			public void keyTyped(KeyEvent arg0) {
				
			}});
        type_predicateCB1.setBounds(200, 100, 150, 37);

        searchvalue.setForeground(new java.awt.Color(255, 255, 255));
        searchvalue.setAlignmentX(0.0F);
        searchvalue.setAlignmentY(0.0F);
        searchvalue.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 91, 127)));
        searchvalue.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
            }
        });
        getContentPane().add(searchvalue);
        searchvalue.setBounds(539, 427, 128, 29);

        type_sujbcetjCB.setEditable(true);
        type_sujbcetjCB.setMaximumRowCount(10);
        type_sujbcetjCB.setBorder(null);
        type_sujbcetjCB.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
            }
        });
        type_sujbcetjCB.getEditor().getEditorComponent().addKeyListener(new KeyListener(){

			@Override
			public void keyPressed(KeyEvent arg0) {
				// TODO Auto-generated method stub
				
			}

			@Override
			public void keyReleased(KeyEvent arg0) {
				if (type_sujbcetjCB.getEditor().getItem()!= null)
				{
					String val = type_sujbcetjCB.getEditor().getItem().toString();
					
					for(String s : subjects_types)
					{
						if (s.contains(val))
						{
							type_sujbcetjCB.setSelectedItem(s);
							break;
						}
					}
				}
			}

			@Override
			public void keyTyped(KeyEvent arg0) {
				
			}});
        getContentPane().add(type_sujbcetjCB);
        type_sujbcetjCB.setBounds(30, 100, 152, 37);

        type_objectCB.setEditable(true);
        type_objectCB.setBorder(null);
        type_objectCB.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
            }
        });
        type_objectCB.getEditor().getEditorComponent().addKeyListener(new KeyListener(){

			@Override
			public void keyPressed(KeyEvent arg0) {
				// TODO Auto-generated method stub
				
			}

			@Override
			public void keyReleased(KeyEvent arg0) {
				if (type_objectCB.getEditor().getItem()!= null)
				{
					String val = type_objectCB.getEditor().getItem().toString();
					
					for(String s : objects_types)
					{
						if (s.contains(val))
						{
							type_objectCB.setSelectedItem(s);
							break;
						}
					}
				}
			}

			@Override
			public void keyTyped(KeyEvent arg0) {
				
			}});
        getContentPane().add(type_objectCB);
        type_objectCB.setBounds(370, 100, 150, 37);

        objectCB.setEditable(true);
        objectCB.setBorder(null);
        objectCB.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
            }
        });
        
        objectCB.getEditor().getEditorComponent().addKeyListener(new KeyListener(){

			@Override
			public void keyPressed(KeyEvent arg0) {
				// TODO Auto-generated method stub
				
			}

			@Override
			public void keyReleased(KeyEvent arg0) {
				if (objectCB.getEditor().getItem()!= null)
				{
					String val = objectCB.getEditor().getItem().toString();
					
					for(String s : objects)
					{
						if (s.contains(val))
						{
							objectCB.setSelectedItem(s);
							break;
						}
					}
				}
			}

			@Override
			public void keyTyped(KeyEvent arg0) {
				
			}});
        
        getContentPane().add(objectCB);
        objectCB.setBounds(371, 49, 150, 37);

        l_w_promieniu1.setText("W promieniu:");
        getContentPane().add(l_w_promieniu1);
        l_w_promieniu1.setBounds(540, 90, 90, 20);
        getContentPane().add(w_promieniu);
        w_promieniu.setBounds(540, 110, 100, 30);
        getContentPane().add(w_promieniu2);
        w_promieniu2.setBounds(620, 110, 30, 30);
        getContentPane().add(w_promieniu1);
        w_promieniu1.setBounds(580, 110, 30, 30);

        l_data.setText("Od:        Do:");
        getContentPane().add(l_data);
        l_data.setBounds(540, 90, 80, 20);
        getContentPane().add(data2);
        data2.setBounds(620, 110, 50, 30);
        getContentPane().add(data1);
        data1.setBounds(600, 110, 50, 30);
        getContentPane().add(data);
        data.setBounds(540, 110, 50, 30);

        jLabel6.setIcon(new javax.swing.ImageIcon("D:\\studia\\TI-7sem\\RDF\\src\\GUI\\bg.jpg")); // NOI18N
        getContentPane().add(jLabel6);
        jLabel6.setBounds(-10, -10, 700, 550);

        
        
        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void sujbcetjCBActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_sujbcetjCBActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_sujbcetjCBActionPerformed


    private void search_mainActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_search_mainActionPerformed
           
    }//GEN-LAST:event_search_mainActionPerformed

    @SuppressWarnings({ "rawtypes", "unchecked" })
	private void loadfileBTActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_loadfileBTActionPerformed
                JFileChooser WybierzPlik = new JFileChooser(".");
                
                if (WybierzPlik.showOpenDialog(null) != JFileChooser.APPROVE_OPTION)
                	return;
                
                File Plik = WybierzPlik.getSelectedFile();
                aRdf = JsonFile.load(Plik.toPath().toString(), RDF[].class);
                
                
                objects.add("");
                objects_types.add("");
                predicats.add("");
                predicats_types.add("");
                subjects.add("");
                subjects_types.add("");
                
                for(RDF rdf : aRdf)
                {
                	if (!objects.contains(rdf.getObject().getName()))
                	{
                		objects.add(rdf.getObject().getName());
                	}
                	
                	if (!predicats.contains(rdf.getProperty().getName()))
                	{
                		predicats.add(rdf.getProperty().getName());
                	}
                	
                	if (!subjects.contains(rdf.getSubject().getName()))
                	{
                		subjects.add(rdf.getSubject().getName());
                	}
                	
                	if (!objects_types.contains(rdf.getObject().getTypeName()))
                	{
                		objects_types.add(rdf.getObject().getTypeName());
                	}
                	
                	if (!predicats_types.contains(rdf.getProperty().getTypeName()))
                	{
                		predicats_types.add(rdf.getProperty().getTypeName());
                	}
                	
                	if (!subjects_types.contains(rdf.getSubject().getTypeName()))
                	{
                		subjects_types.add(rdf.getSubject().getTypeName());
                	}                	                	
                	
                	for (String s : rdf.getObject().getTypeSubTypes())
                	{
                		if (!objects_types.contains(s));
                    	{
                    		objects_types.add(s);
                    	}
                	}
                	
                	for (String s : rdf.getProperty().getTypeSubTypes())
                	{
                		if (!predicats_types.contains(s));
                    	{
                    		predicats_types.add(s);
                    	}
                	}
                	
                	for (String s : rdf.getSubject().getTypeSubTypes())
                	{
                		boolean exists = false;
                		for(String tmp : subjects_types)
                		{
                			if (tmp == s)
                			{
                				exists = true;
                				break;
                			}
                		}
                		
                		if (!exists)
                		{
                			subjects_types.add(s);
                		}
                	}
                }
                
                predicats.add(dateType);
                predicats.add(locationType);
                Collections.sort(objects);
                Collections.sort(predicats);
                Collections.sort(subjects);
                Collections.sort(objects_types);
                Collections.sort(predicats_types);
                Collections.sort(subjects_types);
                
                
                objectCB.setModel(new javax.swing.DefaultComboBoxModel(objects.toArray()));
            	predicateCB.setModel(new javax.swing.DefaultComboBoxModel(predicats.toArray()));
            	subjectsCB.setModel(new javax.swing.DefaultComboBoxModel(subjects.toArray()));
            	type_objectCB.setModel(
            			new javax.swing.DefaultComboBoxModel(objects_types.toArray()));
            	type_predicateCB1.setModel(
            			new javax.swing.DefaultComboBoxModel(predicats_types.toArray()));
            	type_sujbcetjCB.setModel(
            			new javax.swing.DefaultComboBoxModel(subjects_types.toArray()));
    }//GEN-LAST:event_loadfileBTActionPerformed
    
    private boolean isDateFiltered()
    {
    	return predicateCB.getSelectedItem() != null &&
    			!predicateCB.getSelectedItem().toString().isEmpty() &&
    			(
    					predicateCB.getSelectedItem().toString().equals(dateType) /*||
                		dateLex.contains(
                				predicateCB.getSelectedItem().toString())*/
                );
    }
    
    private boolean isLocationFiltered()
    {
    	return predicateCB.getSelectedItem() != null &&
    			!predicateCB.getSelectedItem().toString().isEmpty() &&
    			(
    					predicateCB.getSelectedItem().toString().equals(locationType)/* ||
                		locationLex.contains(
                				predicateCB.getSelectedItem().toString())*/
                );
    }


    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
       
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(GUI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(GUI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(GUI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(GUI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the dialog */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                GUI dialog = new GUI(new javax.swing.JFrame(), true);
                
                dialog.addWindowListener(new java.awt.event.WindowAdapter() {
                    @Override
                    public void windowClosing(java.awt.event.WindowEvent e) {
                        System.exit(0);
                    }
                   
                });
               
                dialog.setVisible(true);
            }
        });
        
    }
    
    /*@Override
    public void paint(Graphics g) {
        Image backgroundImage = null;
		try
		{
			File file = new File("src/GUI/bg.jpg");
			backgroundImage = ImageIO.read(file);
		}
		catch (IOException e)
		{
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
        if(backgroundImage != null)
        	
        	//g.drawImage(backgroundImage, 0, 0, null);

        super.paint(g);
      }*/
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JTextField data;
    private javax.swing.JTextField data1;
    private javax.swing.JTextField data2;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    @SuppressWarnings("rawtypes")
	private javax.swing.JList jList1;
    @SuppressWarnings("rawtypes")
	private javax.swing.JList jList2;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JSeparator jSeparator1;
    private javax.swing.JLabel l_data;
    private javax.swing.JLabel l_w_promieniu1;
    private javax.swing.JButton loadfile1;
    private javax.swing.JButton loadfileBT;
    private javax.swing.JButton saveFileBT;
    private javax.swing.JButton btnClear;
    @SuppressWarnings("rawtypes")
	private javax.swing.JComboBox objectCB;
    private javax.swing.JComboBox<?> predicateCB;
    private javax.swing.JButton search_main;
    private javax.swing.JButton search_main2;
    private javax.swing.JTextField searchvalue;
    private javax.swing.JRadioButton sl_i;
    private javax.swing.JRadioButton sl_lub;
    private javax.swing.ButtonGroup spojniklogiczny;
    @SuppressWarnings("rawtypes")
	private javax.swing.JComboBox subjectsCB;
    private javax.swing.JComboBox<?> type_objectCB;
    @SuppressWarnings("rawtypes")
	private javax.swing.JComboBox type_predicateCB1;
	private javax.swing.JComboBox<?> type_sujbcetjCB;
    private javax.swing.JTextField w_promieniu;
    private javax.swing.JTextField w_promieniu1;
    private javax.swing.JTextField w_promieniu2;
    // End of variables declaration//GEN-END:variables
}